<?php
class Ecourse extends Ecore_Db {
	var $cache;
	var $clear;
	public function __construct() {
		$this->cache = new Ecore_Cache();
		$this->clear = $this->cache->clear;
	}
	public function getAll($intAdtype, $intStatus, $intEcoursId , $intOff, $intLimit, &$intTotal) {
		try {				
			$this->prepare('call educations_cou_getall(?,?,?,?,?)');		
			$this->bindParam(1, $intAdtype, PDO::PARAM_INT, 4);
			$this->bindParam(2, $intStatus, PDO::PARAM_INT, 4);
			$this->bindParam(3, $intEcoursId, PDO::PARAM_INT, 11);
			$this->bindParam(4, $intOff, PDO::PARAM_INT, 11);
			$this->bindParam(5, $intLimit, PDO::PARAM_INT, 4);
			$arrResult 	= $this->fetchAll();
			$intTotal	= isset($arrResult[0]['foundRows']) ? $arrResult[0]['foundRows'] : 0;
			return isset($arrResult) ? $arrResult : null;
		} catch(Exception $e) {
			Ecore_Function::logDb('Backend::Ecourse::getAll - ' .$e->getMessage());
		}
	}
	public function get($intEcoursId) {
		try {						
			$this->prepare('call educations_cou_get(?)');		
			$this->bindParam(1, $intEcoursId, PDO::PARAM_INT, 11);
			$arrResult 	= $this->fetchAll();
			return isset($arrResult[0]) ? $arrResult[0] : null;
		} catch(Exception $e) {
			Ecore_Function::logDb('Backend::Ecourse::get - ' .$e->getMessage());
		}
	}
	public function add($intAdminId, $intEducateId, $strName, $strStart, $intPriceS,
						$intPriceE, $intUnit, $strShort, $strContent, $strTag,
						$intAdv=0, $strFeatures='') {
		try {			
			$this->prepare('call educations_cou_add(?,?,?,?,?,
													?,?,?,?,?,
													?,?)');
			$this->bindParam(1, $intAdminId		, PDO::PARAM_INT, 11);
			$this->bindParam(2, $intEducateId	, PDO::PARAM_INT, 11);
			$this->bindParam(3, $strName		, PDO::PARAM_STR, 255);
			$this->bindParam(4, $strStart		, PDO::PARAM_STR, 10);
			$this->bindParam(5, $intPriceS		, PDO::PARAM_STR, 20);
			$this->bindParam(6, $intPriceE		, PDO::PARAM_STR, 20);
			$this->bindParam(7, $intUnit		, PDO::PARAM_STR, 1);
			$this->bindParam(8, $strShort		, PDO::PARAM_STR, 255);
			$this->bindParam(9, $strContent		, PDO::PARAM_STR);
			$this->bindParam(10, $strTag		, PDO::PARAM_STR, 255);
			$this->bindParam(11, $intAdv		, PDO::PARAM_INT, 4);
			$this->bindParam(12, $strFeatures	, PDO::PARAM_STR);
			$arrResult 	= $this->fetchAll();		
			$intError	= isset($arrResult[0]['errCode']) ? $arrResult[0]['errCode'] : 0;
			if($intError == 0) {
				
			}
			return $intError;
		} catch(Exception $e) {
			Ecore_Function::logDb('Backend::Ecourse::add - ' . $e->getMessage());
			return null;
		}
	}	
	public function update( $intAdminId, $intEcoursId, $intEducateId, $strName, $strStart, 
						$intPriceS, $intPriceE, $intUnit, $strShort, $strContent, 
						$strTag, $intAdv=0, $strFeatures='') {
		try {
			$this->prepare('call educations_cou_update(	?,?,?,?,?,
														?,?,?,?,?,
														?,?,?)');
			$this->bindParam(1, $intAdminId		, PDO::PARAM_INT, 11);
			$this->bindParam(2, $intEcoursId	, PDO::PARAM_INT, 11);
			$this->bindParam(3, $intEducateId	, PDO::PARAM_INT, 11);
			$this->bindParam(4, $strName		, PDO::PARAM_STR, 255);			
			$this->bindParam(5, $strStart		, PDO::PARAM_STR, 10);
			$this->bindParam(6, $intPriceS		, PDO::PARAM_STR, 20);
			$this->bindParam(7, $intPriceE		, PDO::PARAM_STR, 20);
			$this->bindParam(8, $intUnit		, PDO::PARAM_STR, 1);
			$this->bindParam(9, $strShort		, PDO::PARAM_STR, 255);
			$this->bindParam(10, $strContent	, PDO::PARAM_STR);
			$this->bindParam(11, $strTag		, PDO::PARAM_STR, 100);			
			$this->bindParam(12, $intAdv		, PDO::PARAM_INT, 4);
			$this->bindParam(13, $strFeatures	, PDO::PARAM_STR);
			$arrResult 	= $this->fetchAll();		
			$intError	= isset($arrResult[0]['errCode']) ? $arrResult[0]['errCode'] : 0;
			if($intError == 0) {
				
			}
			return $intError;
		} catch(Exception $e) {
			Ecore_Function::logDb('Backend::Ecourse::update - ' . $e->getMessage());
			return null;
		}
	}
	public function updateStatus($intAdminId, $intEcoursId, $intStatus, $intPerm) {
		try {				
			$this->prepare('call educations_cou_update_status(?,?,?,?)');
			$this->bindParam(1, $intAdminId, PDO::PARAM_INT, 11);
			$this->bindParam(2, $intEcoursId, PDO::PARAM_INT, 11);
			$this->bindParam(3, $intStatus, PDO::PARAM_INT, 4);
			$this->bindParam(4, $intPerm, PDO::PARAM_INT, 4);
			$arrResult 	= $this->fetchAll();
			$intError	= isset($arrResult[0]['errCode']) ? $arrResult[0]['errCode'] : 0;
			if($intError == 0) {
				
			}
			return $intError;
		} catch(Exception $e) {
			Ecore_Function::logDb('Backend::Ecourse::updateStatus - ' .$e->getMessage());
		}
	}
	public function delete($intAdminId, $intEcoursId) {
		try {			
			$this->prepare('call educations_cou_delete(?,?)');
			$this->bindParam(1, $intAdminId, PDO::PARAM_INT, 11);
			$this->bindParam(2, $intEcoursId, PDO::PARAM_INT, 11);
			$arrResult 	= $this->fetchAll();
			$intError	= isset($arrResult[0]['errCode']) ? $arrResult[0]['errCode'] : 0;
			if($intError == 0) {
				
			}
			return $intError;
		} catch(Exception $e) {
			Ecore_Function::logDb('Backend::Ecourse::delete - ' .$e->getMessage());
		}
	}
}